#include "berthGrid.h"
#include "Geography/geography.h"
#include "FuzzyToolbox/fuzzytoolbox.h"

#define HEADING_DISTANCE_FACTOR 500  //建议设置为eps的2.5倍

BerthGrid::BerthGrid(quint64 objectID, double longit, double lat, qint16 heading):
    SpatialObjectBase(objectID, longit, lat)
{
    /***基类已经完成了一些变量赋值工作***/
    this->heading=heading;
}

float BerthGrid::distanceTo(SpatialObjectBase*sOB)
{
    BerthGrid *destBerthGrid=(BerthGrid*)sOB; //sOB实际指向的是BerthGrid*
    quint16 absDiffHeading = qAbs(destBerthGrid->heading-this->heading);
    quint16 headingDiff=absDiffHeading>90?180-absDiffHeading:absDiffHeading;
    bool ok;
    float normalisedHeadingDiff = FuzzyToolbox::getUnbalancedSMemberShip(headingDiff,10,30,40,&ok);

    float dist=Geography::GetDistance(getLatitude(),getLongitude(),
             destBerthGrid->getLatitude(),destBerthGrid->getLongitude());
    dist= dist+normalisedHeadingDiff*HEADING_DISTANCE_FACTOR;

    return dist;
}



BerthGrid::~BerthGrid()
{

}

